const mongoose = require("mongoose");
const { collectionsModel } = require("../models/collectionsModel");
//获取所有收藏题目
async function getCollections(req,res){
    let data = await mongoose.model(collectionsModel).find(req.body).populate({
        path:"exerciseId",
        populate:{
            path:"pointId"
        }
    }).populate("studentId");
    res.send({
        message:"响应成功",
        code:200,
        data
    })
}
//删除收藏
async function deleteCollections(req,res){
    await mongoose.model(collectionsModel).deleteOne(req.body)
    let data = await mongoose.model(collectionsModel).find().populate({
        path:"exerciseId",
        populate:{
            path:"pointId"
        }
    }).populate("studentId");
    res.send({
        message:"删除成功",
        code:200,
        data
    })
}
//添加收藏
async function createCollections(req,res){
    await mongoose.model(collectionsModel).create(req.body);
    let data = await mongoose.model(collectionsModel).find().populate({
        path:"exerciseId",
        populate:{
            path:"pointId"
        }
    }).populate("studentId");
    res.send({
        message:"添加成功",
        code:200,
        data
    })
}
module.exports = {
    getCollections,
    deleteCollections,
    createCollections
}